// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
// import com.alibaba.druid.sql.ast.expr.SQLTextLiteralExpr;
// import com.alibaba.druid.sql.ast.expr.SQLValuableExpr;
// import com.alibaba.druid.sql.ast.statement.SQLAssignItem;
// import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
// import com.alibaba.druid.util.FnvHash;

// import java.util.ArrayList;
// import java.util.List;

#include "MysqlCreateFullTextTokenFilterStatement.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/expr/SQLIdentifierExpr.h"
#include "../../../../ast/expr/SQLTextLiteralExpr.h"
#include "../../../../ast/expr/SQLValuableExpr.h"
#include "../../../../ast/statement/SQLAssignItem.h"
#include "../../visitor/MySqlASTVisitor.h"
#include "../../../../../utils/instanceof.h"
#include "../../../../../utils/listTran.h"
#include "../../../../../utils/FnvHash.h"

MysqlCreateFullTextTokenFilterStatement::MysqlCreateFullTextTokenFilterStatement()
{
  options = std::make_shared<std::list<SQLAssignItem_ptr>>();
}

void MysqlCreateFullTextTokenFilterStatement::accept0(MySqlASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(MysqlCreateFullTextTokenFilterStatement)))
  {
    acceptChild(visitor, name);
    acceptChild(visitor, typeName);
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLAssignItem, SQLObject>(options);
    acceptChild(visitor, tmp);
  }
  visitor->endVisit(SharedObject(MysqlCreateFullTextTokenFilterStatement));
}

SQLName_ptr MysqlCreateFullTextTokenFilterStatement::getName()
{
  return name;
}

void MysqlCreateFullTextTokenFilterStatement::setName(SQLName_ptr name)
{
  if (name != nullptr)
  {
    name->setParent(SharedObject(MysqlCreateFullTextTokenFilterStatement));
  }
  this->name = name;
}

SQLTextLiteralExpr_ptr MysqlCreateFullTextTokenFilterStatement::getTypeName()
{
  return typeName;
}

void MysqlCreateFullTextTokenFilterStatement::setTypeName(SQLTextLiteralExpr_ptr typeName)
{
  if (name != nullptr)
  {
    name->setParent(SharedObject(MysqlCreateFullTextTokenFilterStatement));
  }
  this->typeName = typeName;
}

SQLAssignItem_list_ptr MysqlCreateFullTextTokenFilterStatement::getOptions()
{
  return options;
}

void MysqlCreateFullTextTokenFilterStatement::addOption(string_ptr name, SQLExpr_ptr value)
{
  SQLAssignItem_ptr assignItem = SQLAssignItem_ptr(new SQLAssignItem(SQLIdentifierExpr_ptr(new SQLIdentifierExpr(name)), value));
  assignItem->setParent(SharedObject(MysqlCreateFullTextTokenFilterStatement));
  options->push_back(assignItem);
}

SQLExpr_ptr MysqlCreateFullTextTokenFilterStatement::getOption(string_ptr name)
{
  if (name == nullptr)
  {
    return nullptr;
  }

  long hash64 = FnvHash::hashCode64(name);

  for (SQLAssignItem_ptr item : *options)
  {
    SQLExpr_ptr target = item->getTarget();
    if (instanceof <SQLExpr, SQLIdentifierExpr>(target))
    {
      if ((std::dynamic_pointer_cast<SQLIdentifierExpr>(target))->hashCode64() == hash64)
      {
        return item->getValue();
      }
    }
  }

  return nullptr;
}

Object_ptr MysqlCreateFullTextTokenFilterStatement::getOptionValue(string_ptr name)
{
  SQLExpr_ptr option = getOption(name);
  if (instanceof <SQLExpr, SQLValuableExpr>(option))
  {
    return (std::dynamic_pointer_cast<SQLValuableExpr>(option))->getValue();
  }

  return nullptr;
}
